<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserRegister extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
            'mobile'                => 'required|unique:users|regex:/^(1[3456789])\d{9}$/i',
            'password'              => 'required|between:6,20|confirmed',
            'password_confirmation' => 'required|between:6,20'
        ];
    }

    public function messages()
    {
        return [
            'mobile.required'                => '手机号不能为空',
            'mobile.regex'                   => '手机号格式错误',
            'mobile.unique'                  => '手机号已有人使用',
            'password.required'              => '密码不能为空',
            'password.between'               => '密码长度6-20位',
            'password_confirmation.required' => '重复密码不能为空',
            'password_confirmation.between'  => '重复密码长度6-20位',
            'password.confirmed'             => '两次密码不一致'
        ];
    }
}
